﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.AlarmHistory;
using AppSocketService.AlarmHistoryPerson;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Phone.AlarmHistory
{
    /// <summary>
    /// 个人用户手机端报警历史记录
    /// </summary>
    [ApiExplorerSettings(GroupName = "PersonApp")]
    [Route("api/[controller]")]
    [ApiController]
    public class PhoneAlarmHistoryPersonController : PhoneBaseController
    {
        private readonly IAlarmNotifyHistoryPersonService alarmNotifyHistoryPersonService;

        #region 构造函数
        /// <summary>
        /// 
        /// </summary>
        /// <param name="alarmNotifyHistoryPersonService"></param>
        public PhoneAlarmHistoryPersonController(IAlarmNotifyHistoryPersonService alarmNotifyHistoryPersonService)
        {
            this.alarmNotifyHistoryPersonService = alarmNotifyHistoryPersonService;
        }
        #endregion

        /// <summary>
        /// 查询报警记录
        /// </summary> 
        /// <param name="imei">IMEI</param>
        /// <param name="alarmType">报警类型</param>
        /// <param name="notifyType">报警通知类型</param>
        /// <param name="isConfirm">是否已确认</param>
        /// <param name="isDelete">是否已删除</param>
        /// <param name="desc"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<AlarmNotifyHistoryDto>), 200)]
        public ActionResult<PageableList<AlarmNotifyHistoryDto>> QueryPage(string imei, AlarmType? alarmType, AlarmNotifyType? notifyType, bool? isConfirm, bool? isDelete = false, bool? desc = false, int? index = 0, int? size = 20)
        {
            if (index > 0)
                index--;
            return alarmNotifyHistoryPersonService.GetListPerson(imei, alarmType, notifyType, isConfirm, isDelete.Value, desc.Value, index.Value, size.Value);
        }

        /// <summary>
        /// 报警确认
        /// </summary>
        /// <param name="id">报警记录Id</param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(OkResult), 200)]
        public ActionResult AlarmConfirm(string id)
        {
            alarmNotifyHistoryPersonService.AlarmConfirm(id);
            return new OkResult();
        }

        /// <summary>
        /// 批量报警确认
        /// </summary>
        /// <param name="idList">报警记录列表Id</param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(OkResult), 200)]
        public ActionResult AlarmListConfirm(List<string> idList)
        {
            alarmNotifyHistoryPersonService.AlarmConfirm(idList);
            return new OkResult();
        }

        /// <summary>
        /// 批量报警确认
        /// </summary>
        /// <param name="imeiList">IMEI数组</param>
        /// <param name="alarmType">报警类型</param>
        /// <param name="notifyType">报警通知类型</param>
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(OkResult), 200)]
        public ActionResult AlarmConfirmAll(List<string> imeiList, AlarmType? alarmType, AlarmNotifyType? notifyType)
        { 
            alarmNotifyHistoryPersonService.AlarmConfirm(imeiList, alarmType,notifyType);
            return new OkResult();
        }
    }
}